package com.payroll.taglib.html;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts.util.ResponseUtils;

/**
 * Prints the page banner.
 * @author: Framework Administrator
 */
public class PageBannerTag extends TagSupport {

	/**
     *
     */
    private static final long serialVersionUID = -6670421247180561917L;

    private boolean showToolRefresh = false ;
    private boolean forModal = false;
/**
 * SavePromptTag constructor comment.
 */
public PageBannerTag() {
	super();
}
	/**
	 * Process the end of this tag.
	 * @exception JspException if a JSP exception has occurred
	 */
	public int doEndTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		String m_contextRoot = request.getContextPath();

		StringBuffer results = new StringBuffer(800);
		results.append("<div id=\"divBanner\">");
        results.append("<table class=\"toolbar\">");
		results.append("<tbody>");
		results.append("<tr>");

        // "Error"

        results.append("" +
                "<td>" +
                "<button onclick=\"initializeError();\" style=\"visibility: hidden;\" id=\"linkErrors\">" +
                "<span>Errors</span><img alt=\"\" tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_error.gif\">" +
                "</button>" +
                "</td>");

		if (showToolRefresh) {

            // "Refresh"

            results.append("" +
                    "<td>" +
                    "<button onclick=\"showToolRefresh();\" >" +
                    "<span>Refresh</span><img alt=\"\" tabindex=\"-1\" src=\"" + m_contextRoot + "/images/tool_refresh.gif\">" +
                    "</button>" +
                    "</td>");
		}

        // "Print"

        results.append("" +
                "<td>" +
                "<button onclick=\"printPage();\">" +
                "<span>Print</span><img alt=\"\" tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_print.gif\">" +
                "</button>" +
                "</td>");

        results.append("" +
                "<td>" +
                "<button onclick=\"showAudit();\">" +
                "<span>Audit</span><img alt=\"\" tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_audit.gif\">" +
                "</button>" +
                "</td>");

		// Only show pen icon if offlineMode
		/*if(com.ams.framework.Foundation.isOffline()) {
			if(com.ams.framework.Foundation.getProperty("offlineHardware").equalsIgnoreCase("tablet")) {
				results.append("<td width=\"28\" class=\"toolLabel\" nowrap=\"true\" valign=\"middle\" align=\"right\">&nbsp;&nbsp;&nbsp;Write</td><td width=\"10\"><SPAN onclick=\"javascript:penWrite();\" accesskey=\"c\" onkeypress=\"if(event.keyCode==32) javascript:penWrite()\"><img  style='cursor:hand' tabindex=0 src=\"" + m_contextRoot +  "/images/tool_pen.gif\" border=\"0\" hspace=\"0\"></SPAN></td>");
			}
		}*/

        // "Spell Check"
        if(forModal){
        results.append("" +
                "<td>" +
                "<button onclick=\"javascript:initializeSpellCheck();\">" +
                "<span>Spell Check</span><img alt=\"\" tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_spell.gif\">" +
                "</button>" +
                "</td>");
        }else{
            results.append("" +
                    "<td>" +
                    "<button onclick=\"javascript:spellCheck();\">" +
                    "<span>Spell Check</span><img alt=\"\" tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_spell.gif\">" +
                    "</button>" +
                    "</td>");
        }
        // Either "View Source" or "Launch Help"

		if (com.payroll.framework.Foundation.getProperty("developerMode").equalsIgnoreCase("on")){
            results.append(
                    "<td>" +
                    "<button onclick=\"viewSource" + (forModal ? "('iframe',window.frames['jspFrame'])": "('tag', document.getElementsByTagName('HTML'))") + ";\">Source</button>" +
                    "</td>");
		} else {
            results.append(
                    "<td>" +
                    "<button onclick=\"launchHelp(top.document.title);\">" +
                    "<span>Help</span><img tabIndex=\"-1\" src=\"" + m_contextRoot + "/images/tool_help.gif\">" +
                    "</button>" +
                    "</td>");
		}

		results.append("</tr>");
		results.append("</tbody>");
		results.append("</table>");
		results.append("</div>");

//	end mbj

		// Render this element to our writer
		ResponseUtils.write(pageContext, results.toString());

		// Evaluate the remainder of this page
		return (EVAL_PAGE);

	 }
	/**
	 * @return
	 */
	public boolean isShowToolRefresh() {
		return showToolRefresh;
	}

	/**
	 * @param b
	 */
	public void setShowToolRefresh(boolean b) {
		showToolRefresh = b;
	}
    public boolean isForModal() {
        return forModal;
    }
    public void setForModal(boolean forModal) {
        this.forModal = forModal;
    }

}
